package com.samuel.basics.controller.api;

import com.samuel.basics.entity.UserEntity;
import com.samuel.basics.model.ResultVo;
import com.samuel.basics.model.ResultVoUtil;
import com.samuel.basics.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p></p>
 *
 * @author kaiji
 * @since 2021-01-21 21:04:45
 */
@CrossOrigin
@RestController("apiUserController")
@RequestMapping("api")
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping("login")
    public ResultVo login(@RequestBody UserEntity userEntity) {
        UserEntity entity = userService.lambdaQuery()
                .eq(UserEntity::getPhone, userEntity.getUsername())
                .eq(UserEntity::getPassword, userEntity.getPassword()).one();

        if (null == entity) {
            return ResultVoUtil.error(999, "登陆错误");
        }
        return ResultVoUtil.success(entity);
    }

}
